<template>
  <div class="block">
    <el-date-picker
      v-model="value"
      type="date"
      placeholder="选择日期"
      :picker-options="pickerOptions"
      @change="pickChange"
      @focus="disabledDateChange"
    />
  </div>
</template>

<script>
export default {
  props: {
    value01: {
      type: String,
      default: ''
    },
    // 控制是否限制日期选择
    isDisabledDate: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      value: '',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      }
    }
  },
  created() {
    this.toCnTime()
  },
  methods: {
    pickChange(val) {
      console.log(val)
      this.$emit('datePickVal', val)
    },
    disabledDateChange() {
      if (this.isDisabledDate) {
        return false
      } else {
        this.pickerOptions = {}
      }
    },
    toCnTime() {
      const dateTime = new Date(parseInt(this.value01, 10))
      console.log(dateTime)
      this.value = dateTime
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
